<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="/lib/layui/css/layui.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <div class="form-group">
                <label class="col-md-2 control-label">模块名称</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="模块名称" type="text" name="name" id="name"
                           data-bv-notempty="true"
                           data-bv-notempty-message="模块名称 不能为空">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">访问路径</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="访问路径 type="text" name="indexPage" id="indexPage" data-bv-notempty="true"
                           data-bv-notempty-message="访问路径 不能为空">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">是否展示</label>
                <div class="col-md-10">
                    <select name="ifShow" class="form-control input-sm" id="ifShow">
                        <option value="1">展示</option>
                        <option value="0">不展示</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">排序</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="排序" name="sort" id="sort" type="number" value="100"
                           data-bv-notempty="true"
                           data-bv-notempty-message="排序 不能为空">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">描述</label>
                <div class="col-md-10">
                    <textarea class="layui-textarea" name="description" id="description"></textarea>
                </div>
            </div>

            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='list.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>	
	<script type="text/javascript" src="/js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="/js/jq.js"></script>
	<script type="text/javascript" src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="/js/common.js"></script>
	<script type="text/javascript" src="/js/my/roles/role.js"></script>
	<script type="text/javascript" src="/lib/layui/layui.js"></script>
	<script type="text/javascript" src="/js/dict.js"></script>
	<script type="text/javascript">
	layui.use(['layer','laydate'], function(){
	    var layer = layui.layer;
	    var laydate = layui.laydate;
	    laydate.render({
           elem: '#birthday'
        });
	});
	initData();
	
	function initData(){
		var id = getUrlParam("id");
		if(id != ""){
			$.ajax({
				type : 'get',
				url : '/sys/module/'+id,
				async : false,
				success : function(data) {
					$("#id").val(data.id);
					$("#name").val(data.name);
					$("#indexPage").val(data.indexPage);
                    $("#ifShow").val(data.ifShow);
					$("#sort").val(data.sort);
					$("#description").val(data.description);
				}
			});
		}
	}
	
		$('#form').bootstrapValidator();
		
		function update() {
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();

			$.ajax({
				type : 'put',
				url : '/sys/module',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					layer.msg("修改成功", {shift: -1, time: 1000}, function(){
                        location.href = "list.html";
                    });
				}
			});
		}
		
	</script>
</body>
</html>